package com.qtummatrix.controller;

import com.opensymphony.xwork2.ActionSupport;
import com.qtummatrix.entity.ClientEntity;
import com.qtummatrix.service.UploadingService;
import com.qtummatrix.utils.ReadExcel;
import jxl.read.biff.BiffException;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 马鹏鑫
 * Created by 86176 on 2019/11/21 19:39
 */
@Controller("credit")
public class Credit extends ActionSupport {
    private String name;
    private String six;
    private Map<String, Object> info = new HashMap();

    private String customer;
    private String bankq;


    String numbering;//贷款编号
    String numbered;//客户编号
    String customerName;//客户名称
    String product;//产品名称
    String state;//状态
    String Rabobank;//所属银行


    private int Mini;//获取id

    public int getMini() {
        return Mini;
    }

    public void setMini(int mini) {
        Mini = mini;
    }

    public String getNumbering() {
        return numbering;
    }

    public String getNumbered() {
        return numbered;
    }

    public String getCustomerName() {
        return customerName;
    }

    public String getProduct() {
        return product;
    }

    public String getState() {
        return state;
    }

    public String getRabobank() {
        return Rabobank;
    }

    public void setNumbering(String numbering) {
        this.numbering = numbering;
    }

    public void setNumbered(String numbered) {
        this.numbered = numbered;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public void setState(String state) {
        this.state = state;
    }

    public void setRabobank(String rabobank) {
        Rabobank = rabobank;
    }

    public String getCustomer() {
        return customer;
    }

    public String getBankq() {
        return bankq;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public void setBankq(String bankq) {
        this.bankq = bankq;
    }

    public UploadingService getUploadingService() {
        return uploadingService;
    }

    public void setUploadingService(UploadingService uploadingService) {
        this.uploadingService = uploadingService;
    }

    public Map<String, Object> getInfo() {
        return info;
    }

    public void setInfo(Map<String, Object> info) {
        this.info = info;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSix() {
        return six;
    }

    public void setSix(String six) {
        this.six = six;
    }

    @Autowired
    private UploadingService uploadingService;


    /**
     * 添加信誉评分额度
     *
     * @return
     */
    public String getList() {
        List<Map<String, Object>> strings = uploadingService.upMess();
        info.put("list", strings);
        return SUCCESS;
    }

    /**
     * 读取Excel表格
     *
     * @return
     * @throws IOException
     * @throws BiffException
     */
    public String getmap() throws IOException, BiffException {
        ReadExcel readExcel = new ReadExcel();
        List<ClientEntity> KO = readExcel.hu();
        for (int i = 0; i < KO.size(); i++) {
            info.put("list", KO.get(i));
        }
        return SUCCESS;
    }


    /**
     * 获取银行列表
     *
     * @return
     */
    public String getbank() {
        List<Map<String, Object>> strings = uploadingService.getAllBankName();

        info.put("Bank", strings);
        return SUCCESS;
    }

    //根据条件查询信息
    public String getMessage() {
        HttpServletRequest request = ServletActionContext.getRequest();
        String page = request.getParameter("pageNo");//当前页数
        String rows = request.getParameter("pageSize");//当前条数
        String name = getCustomer();
        String bank = getBankq();
        List<Map<String, Object>> information = uploadingService.getInformation(name, bank,
                (Integer.parseInt(page) - 1) * Integer.parseInt(rows), Integer.parseInt(rows));
        info.put("list", information);
        int total = uploadingService.miao(name, bank);
        int pages = total % Integer.parseInt(rows) == 0 ? total / Integer.parseInt(rows)
                : total / Integer.parseInt(rows) + 1;
        info.put("pageNum", page);//当前页数
        info.put("pages", pages);//总页数
        info.put("total", total);//总条数

        return SUCCESS;
    }

    /**
     * 查询产品
     *
     * @return
     */
    public String getPHY() {
        List<Map<String, Object>> mapP = uploadingService.getProduct();
        info.put("PHY", mapP);
        return SUCCESS;
    }

    /**
     * 查询审批状态
     *
     * @return
     */
    public String getStat() {

        List<Map<String, Object>> mapP = uploadingService.getState();
        info.put("Stat", mapP);
        return SUCCESS;
    }

    /**
     * 根据条件查找
     *
     * @return
     */
    public String getqtummm() {
        HttpServletRequest request = ServletActionContext.getRequest();
        String page = request.getParameter("pageNo");//当前页数
        String rows = request.getParameter("pageSize");//当前条数
        String snumbering = getNumbering();
        String snumbered = getNumbered();
        String scustomerName = getCustomerName();
        String sproduct = getProduct();
        String sstate = getState();
        String sRabobank = getRabobank();
        List<Map<String, Object>> accommodation = uploadingService.getAccommodation(snumbering, snumbered,
                scustomerName, sproduct, sstate, sRabobank, (Integer.parseInt(page) - 1) * Integer.parseInt(rows),
                Integer.parseInt(rows));
        int total = uploadingService.tiao(snumbering, snumbered, scustomerName, sproduct, sstate, sRabobank);//总条数
        //总页数
        int pages = total % Integer.parseInt(rows) == 0 ? total / Integer.parseInt(rows)
                : total / Integer.parseInt(rows) + 1;
        info.put("list", accommodation);
        info.put("pageNum", page);//当前页数
        info.put("pages", pages);//总页数
        info.put("total", total);//总条数
        return SUCCESS;
    }

    /**
     * 根据ID查询客户的基本信息
     *
     * @return
     */
    public String GetingInfo() {
        int Wd = getMini();
        List<Map<String, Object>> mapList = uploadingService.GettingInformation(Wd);
        System.out.println(mapList);
        info.put("list", mapList);
        return SUCCESS;
    }


}